import {squareMap} from "@/assets/js/squareMap";

function getCodeById(id: string) {
    for(const key of Object.keys(squareMap)){
        if(squareMap[key] === id){
            return Number(key)
        }
    }
    return null
}
export default class Monster {
    private type: string;
    private survival: boolean;
    constructor(
        public readonly id: string,
        public square?: number
    ) {
        this.id = id
        this.type = 'monster'
        this.survival = true // 是否存活
        if(square){
            this.square = square
        }else {
            const code = getCodeById(id)
            if(code){
                this.square = code
            }else{
                throw new Error("Id is illegal.")
            }
        }
    }
    startBattle(){
        this.square = 1
    }
}
